#pragma once
#ifndef Convertor_h__
#define Convertor_h__

#include <QDataStream>
#include <QCryptographicHash>
#include <QByteArray>
#include <QString>
#include <QVariantMap>
#include <QIODevice>

namespace TCServer
{
    namespace Utility
    {
        class Convertor
        {
        public:
            static QString sqlUrlEncode(const QString &url)
            {
                return url;
            }
            static QString sqlUrlDecode(const QString &data)
            {
                return data;
            }
            static QByteArray toMd5Hash(const QByteArray &data)
            {
                return QCryptographicHash::hash(data, QCryptographicHash::Md5);
            }
            static QString toPasswordHash(const QString &password)
            {
                return toMd5Hash((password + "HappyZhSecurity").toUtf8()).toHex();
            }
            static QByteArray toByteArray(const QVariantMap &val)
            {
                QByteArray data;
                QDataStream stream(&data, QIODevice::WriteOnly);
                stream << val;
                return data;
            }
            static QVariantMap toVariantMap(const QByteArray &val)
            {
                QVariantMap obj;
                QDataStream stream(val);
                stream >> obj;
                return obj;
            }
        };
    }
}

#endif // Convertor_h__
